package view.mediator.monster.large_monster
{
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	import model.monster.MonsterModel;
	import model.vo.monster.SpVo;
	
	import org.robotlegs.mvcs.StarlingMediator;
	
	import view.component.monster.large_monster.LMVideoListView;
	import view.event.monster.LMVideoListViewEvent;
	import view.event.monster.LMonsterVideoListItemEvent;
	
	
	/**
	 * LMDetailVideoView界面中介
	 * @author £iang
	 * 
	 */	
	public class LMVideoListViewMediator extends StarlingMediator
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** LMDetailVideoView界面 */
		[Inject]
		public var lMDetailVideoView:LMVideoListView;
		/** monsterModel */
		[Inject]
		public var monsterModel:MonsterModel;
		
		//-----------------------------
		// properties
		//-----------------------------
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 注册函数 
		 * 
		 */		
		override public function onRegister():void
		{
			addViewListener( LMonsterVideoListItemEvent.START_EDIT, startEditHandler );
			addViewListener( LMonsterVideoListItemEvent.START_DELETE, startDeleteHandler );
			addViewListener( LMonsterVideoListItemEvent.PLAY, playHandler );
			addViewListener( LMVideoListViewEvent.START_ADD, startAddHandler );
			addContextListener( LMVideoListViewEvent.UPDATE_LIST, updateListHandler );
			lMDetailVideoView.setListData( monsterModel.curLMonsterVideoData );
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		/**
		 * 处理点击编辑按钮后派发的事件 
		 * @param event 点击编辑按钮后派发的事件 
		 * 
		 */		
		protected function startEditHandler( event:LMonsterVideoListItemEvent ):void
		{
			monsterModel.curVideoOperation = "edit";
			monsterModel.curDealingVideo = event.data;
			dispatch( event );
		}
		
		/**
		 * 处理点击添加按钮后派发的事件 
		 * @param event 点击添加按钮后派发的事件 
		 * 
		 */		
		protected function startAddHandler( event:LMVideoListViewEvent ):void
		{
			monsterModel.curVideoOperation = "add";
			monsterModel.curDealingVideo = new SpVo();
			dispatch( event );
		}
		
		/**
		 * 处理点击删除按钮后派发的事件 
		 * @param event 点击删除按钮后派发的事件 
		 * 
		 */		
		protected function startDeleteHandler( event:LMonsterVideoListItemEvent ):void
		{
			monsterModel.curDealingVideo = event.data;
			dispatch( event );
		}
		
		/**
		 * 处理点击观看按钮后派发的事件 
		 * @param event 点击观看按钮后派发的事件 
		 * 
		 */		
		protected function playHandler( event:LMonsterVideoListItemEvent ):void
		{
			navigateToURL( new URLRequest( event.data.url ), "_blank" );
		}
		
		/**
		 * 处理请求更新列表后派发的事件 
		 * @param event 请求更新列表后派发的事件 
		 * 
		 */		
		protected function updateListHandler( event:LMVideoListViewEvent = null ):void
		{
			lMDetailVideoView.initData();
			lMDetailVideoView.setListData( monsterModel.curLMonsterVideoData );
			lMDetailVideoView.playShowAnimate();
		}
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 移除函数 
		 * 
		 */		
		override public function onRemove():void
		{
			removeViewListener( LMonsterVideoListItemEvent.START_EDIT, startEditHandler );
			removeViewListener( LMonsterVideoListItemEvent.START_DELETE, startDeleteHandler );
			removeViewListener( LMonsterVideoListItemEvent.PLAY, playHandler );
			removeViewListener( LMVideoListViewEvent.START_ADD, startAddHandler );
			removeContextListener( LMVideoListViewEvent.UPDATE_LIST, updateListHandler );
			super.onRemove();
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function LMVideoListViewMediator()
		{
			super();
		}
	}
}